www.gusucode.com > VC编写的串口调试软件 > VC编写的串口调试软件,内含Modbus协议类 支持对Modbus通讯调试/Modbus串口调试软件1.0/com/RectLight.cpp
// RectLight.cpp : implementation file // #include "stdafx.h" #include "RectLight.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CRectLight CRectLight::CRectLight() { m_unOnStyle=0; m_unOffStyle=0; m_unState=0; } CRectLight::~CRectLight() { } BEGIN_MESSAGE_MAP(CRectLight, CButton) //{{AFX_MSG_MAP(CRectLight) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CRectLight message handlers void CRectLight::PreSubclassWindow() { // TODO: Add your specialized code here and/or call the base class ModifyStyle(0, BS_OWNERDRAW); CButton::PreSubclassWindow(); } void CRectLight::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { // TODO: Add your code to draw the specified item ASSERT(lpDrawItemStruct != NULL); CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); CRect rect = lpDrawItemStruct->rcItem; UINT state = lpDrawItemStruct->itemState; UINT nStyle = GetStyle(); int nCheck=GetCheck(); if(m_unState) // if (state & ODS_SELECTED || state & ODS_FOCUS || nCheck==1 ) pDC->FillSolidRect (&rect,m_clrOn); else pDC->FillSolidRect (&rect,m_clrOff); pDC->FrameRect (rect,&CBrush(GetSysColor(COLOR_3DSHADOW))); for(int i=2;i<7;i++) { if(1==m_unState) { if(0==m_unOnStyle) break; if(1==m_unOnStyle && i==6) //单凹 break; if(2==m_unOnStyle && i==4) //双凹 continue; if(3==m_unOnStyle && i==6) //单凸 break; if(4==m_unOnStyle && i==4) //双凸 continue; COLORREF clrTopLeft; COLORREF clrBottomRight ; switch(m_unOnStyle) { case 1: case 2: { clrTopLeft=GetSysColor(COLOR_3DSHADOW); clrBottomRight=GetSysColor(COLOR_BTNHIGHLIGHT); break; } case 3: case 4: { clrTopLeft=GetSysColor(COLOR_BTNHIGHLIGHT); clrBottomRight=GetSysColor(COLOR_3DSHADOW); break; } default: ; } pDC->Draw3dRect (rect.left+i,rect.top+i,rect.Width ()-2*i,rect.Height ()-2*i, clrTopLeft,clrBottomRight); if(5==m_unOnStyle) break; } else if(0==m_unState) { if(0==m_unOffStyle) break; if(1==m_unOffStyle && i==6) //单凹 break; if(2==m_unOffStyle && i==4) //双凹 continue; if(3==m_unOffStyle && i==6) //单凸 break; if(4==m_unOffStyle && i==4) //双凸 continue; COLORREF clrTopLeft; COLORREF clrBottomRight ; switch(m_unOffStyle) { case 1: case 2: { clrTopLeft=GetSysColor(COLOR_3DSHADOW); clrBottomRight=GetSysColor(COLOR_BTNHIGHLIGHT); break; } case 3: case 4: { clrTopLeft=GetSysColor(COLOR_BTNHIGHLIGHT); clrBottomRight=GetSysColor(COLOR_3DSHADOW); break; } default: ; } pDC->Draw3dRect (rect.left+i,rect.top+i,rect.Width ()-2*i,rect.Height ()-2*i, clrTopLeft,clrBottomRight); if(5==m_unOffStyle) break; } } CString strTxt; GetWindowText(strTxt); pDC->SetBkMode(TRANSPARENT); pDC->DrawText (strTxt,rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER); } unsigned int CRectLight::SetState(unsigned int nState) { unsigned int unOldState=m_unState; if(m_unState!=nState) { m_unState=nState; RedrawWindow (); } return unOldState; } void CRectLight::SetParam(COLORREF clrOn,unsigned int unOnStyle,COLORREF clrOff,unsigned int unOffStyle=5) { m_clrOn=clrOn; m_clrOff=clrOff; m_unOnStyle=unOnStyle; m_unOffStyle=unOffStyle; } unsigned int CRectLight::GetState() { return m_unState; }